<script setup>
import {getNowTime} from '@/utils/time'
import {useRouter} from 'vue-router'
import {ref,onMounted,onBeforeUnmount} from 'vue'

let nowTime = ref()  // 保存当前时间
let timer = ref()  // 保存定时器，后面关闭用

let $router = useRouter()
const goHome = () => {
    $router.push('/home')
}

onMounted(()=>{
    // 设置定时器，用来动态显示时间
    timer.value = setInterval(()=>{
        nowTime.value = new getNowTime().format("yyyy年MM月dd日 hh:mm:ss")
    },1000)
})
onBeforeUnmount(()=>{
    clearInterval(timer.value)
})


</script>

<template>
    <div class="top">
        <div class="left">
            <span class="lbtn" @click="goHome">首页</span>
        </div>
        <div class="center">
            <div class="title">智慧旅游可视化大数据平台</div>
        </div>
        <div class="right">
            <span class="rbtn">统计报告 </span>
            <span class="time">当前时间：{{ nowTime }}</span>
        </div>
    </div>
</template>

<style scoped lang="scss">
.top{
    width: 100%;
    height: 100%;
    display: flex;
    color: #29fcff;
    
    .left{
        flex:1;
        background: url('/public/img/screen/dataScreen-header-left-bg.png')  no-repeat;
        background-size: cover;
        .lbtn{
            width: 150px;
            height: 40px;
            float: right;
            background: url('/public/img/screen/dataScreen-header-btn-bg-l.png')  no-repeat;
            background-size: 100% 100%;
            text-align: center;
            line-height: 40px;
            font-size: 20px;
            cursor: pointer;
        }
        .lbtn:hover{
            background-color: #5f99db;
        }
    }
    .center{
        flex: 2;
        .title{
            width:100%;
            height: 74px;
            background: url('/public/img/screen/dataScreen-header-center-bg.png') no-repeat;
            background-size: 100% 100%;
            text-align: center;
            line-height: 74px;
            font-size: 30px;
            
        }
    }
    .right{
        flex: 1;
        background: url('/public/img/screen/dataScreen-header-left-bg.png') no-repeat;
        background-size: cover;
        display: flex;
        // justify-content: space-between;
        align-items: center;
        .rbtn{
            width: 150px;
            height: 40px;
            background: url('/public/img/screen/dataScreen-header-btn-bg-r.png') no-repeat;
            text-align: center;
            line-height: 40px;
            font-size: 20px;
        }
    }
}
</style>